; LPMolecularViewer Install.nsi
;
; This script is based on example2.nsi,
; It installs the LPDataPlotShellExtension, registers it and setups the uninstaller.
; Uninstaller unregisters the dll and clears up everything.

;Sets useful variables
!define APP_NAME "LPMolecularViewer"
!define UN_REG_LOCATION "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}"

;--------------------------------
; The name of the installer
;Name "Install LPMolecularViewer"
Name "Install ${APP_NAME}"

; The file to write
;OutFile "LPMolecularViewer Install.exe"
OutFile "${APP_NAME} Install.exe"

; The default installation directory
InstallDir $PROGRAMFILES\LPUtils

; Registry key to check for directory (so if you install again, it will 
; overwrite the old one automatically)
;InstallDirRegKey HKLM "Software\NSIS_Example2" "Install_Dir"

; Request application privileges for Windows Vista
RequestExecutionLevel admin

;--------------------------------

; Pages

;Page components
Page directory
Page instfiles

;UninstPage uninstConfirm
;UninstPage instfiles

;--------------------------------

; The stuff to install
Section ""

  ;SectionIn RO
 
  ; Set output path to the installation directory.
  SetOutPath $INSTDIR
  
  ; Put files here
  File "..\ReleaseMinSize\LPMolecViewerControl.dll"
  File "..\TestMolecViewerControl.ppt"
  File "..\ethanol.xyz"
  File "..\molecule.xyz"
  File "..\Br2-PTCDI.pdb"
  
  ;Register dll
  RegDLL LPMolecViewerControl.dll
  
  ; Write the installation path into the registry
  ;WriteRegStr HKLM SOFTWARE\NSIS_Example2 "Install_Dir" "$INSTDIR"
  
  ; Write the uninstall keys for Windows
  ;WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\LPMolecularViewer" "DisplayName" "LPMolecularViewer"
  WriteRegStr HKLM ${UN_REG_LOCATION} "DisplayName" ${APP_NAME}
  
  ;WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\LPMolecularViewer" "UninstallString" '"$INSTDIR\uninstall.exe"'
  WriteRegStr HKLM ${UN_REG_LOCATION} "UninstallString" '"$INSTDIR\uninstall.exe"'
  
  ;WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\LPMolecularViewer" "NoModify" 1
  WriteRegDWORD HKLM ${UN_REG_LOCATION} "NoModify" 1
  
  ;WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\LPMolecularViewer" "NoRepair" 1
  WriteRegDWORD HKLM ${UN_REG_LOCATION} "NoRepair" 1
  
  WriteUninstaller "uninstall.exe"
  
SectionEnd

; Optional section (can be disabled by the user)
;Section "Start Menu Shortcuts"

;  CreateDirectory "$SMPROGRAMS\Example2"
;  CreateShortCut "$SMPROGRAMS\Example2\Uninstall.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0
;  CreateShortCut "$SMPROGRAMS\Example2\Example2 (MakeNSISW).lnk" "$INSTDIR\example2.nsi" "" "$INSTDIR\example2.nsi" 0
  
;SectionEnd

;--------------------------------

; Uninstaller

Section "Uninstall"
  
  ;Unregister dll
  UnRegDLL "$INSTDIR\LPMolecViewerControl.dll"
  
  ; Remove registry keys
  DeleteRegKey HKLM ${UN_REG_LOCATION}
;  DeleteRegKey HKLM SOFTWARE\NSIS_Example2

  ; Remove files and uninstaller
  ;Delete $INSTDIR\example2.nsi
  Delete $INSTDIR\uninstall.exe
  Delete $INSTDIR\LPMolecViewerControl.dll
  Delete $INSTDIR\TestMolecViewerControl.ppt
  Delete $INSTDIR\ethanol.xyz
  Delete $INSTDIR\Br2-PTCDI.pdb
  ; Remove shortcuts, if any
;  Delete "$SMPROGRAMS\Example2\*.*"

  ; Remove files and directories used
  ;RMDir "$SMPROGRAMS\Example2"
  RMDir "$INSTDIR"

SectionEnd
